package com.lc.luzhengtang.adapter;

import android.content.Intent;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lc.luzhengtang.R;
import com.lc.luzhengtang.activity.MarqueueWebActivity;
import com.lc.luzhengtang.bean.NewsBean;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * 文 件 名: NewsListAdapter
 * 创 建 人: zhangyu
 * 创建日期: 16/12/24 19:55
 * 邮   箱: yuanchong121@gmail.com
 * 修改时间：
 * 修改备注：
 */
public class NewsListAdapter extends BaseQuickAdapter<NewsBean.DataBeanX.DataBean, BaseViewHolder> {
    public NewsListAdapter(List<NewsBean.DataBeanX.DataBean> data) {

        super(R.layout.item_edit_news, data);
    }


    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void convert(BaseViewHolder helper, final NewsBean.DataBeanX.DataBean item) {
        ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) helper.convertView);
        helper.setText(R.id.text_newstitle, item.getTitle());
        helper.setText(R.id.text_newstime, item.getCreate_time());
        if (item.getState() == 1) {
            helper.setText(R.id.text_flag, "未读");
            helper.setTextColor(R.id.text_flag, mContext.getColor(R.color.searchcolor));

//            background_circle_gray
            helper.setBackgroundRes(R.id.view_back_news, R.drawable.background_circle_gray);
// /            helper.setBackgroundRes(R.id.view_back_news,mContext.getResources().getDrawable(R.drawable.background_circle_gray));
        } else if (item.getState() == 2) {
            helper.setText(R.id.text_flag, "已读");
        }

        View view = helper.getConvertView();

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("url", "http://luzhengtang.cn/index.php/api/pushinfo/info?id=" + item.getId() + "");
                intent.setClass(mContext, MarqueueWebActivity.class);
                mContext.startActivity(intent);
            }
        });


    }


}
